package com.itheima.shop.strategy_review;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @program: design
 * @description:
 * @author: zhanghz001
 * @create: 2021-02-27 20:04
 **/
@Component
@ConfigurationProperties(prefix = "strategy")
@Data
public class StrateFactoryReview implements ApplicationContextAware {
    private Map<Integer, String> strategyMap;
    private ApplicationContext cxt;
    
    public VipMoneyReview get(Integer level) {
        String beanId = strategyMap.get(level);
        VipMoneyReview vipMoneyReview = cxt.getBean(beanId, VipMoneyReview.class);
        return vipMoneyReview;
    }
    
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.cxt = applicationContext;
        
    }
}
